package com.study.flink.datastream

import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment

/**
  * Flink Partition Demo
  *
  * @author stephen
  * @create 2019-05-25 12:29
  * @since 1.0.0
  */
object FlinkPartitionDemo {

  def main(args: Array[String]): Unit = {
    // 1、执行环境
    val env = StreamExecutionEnvironment.getExecutionEnvironment

    // 2、指定数据源
    import org.apache.flink.api.scala._
    val dataStream = env.fromElements(("a", 1), ("b", 2), ("c", 3), ("a", 1), ("a", 1), ("b", 1), ("a", 1), ("b", 1))

    // 3、对数据进行操作
    // 随机分区
    //val resultStream = dataStream.shuffle
    // 平衡分区
    val resultStream = dataStream.rebalance
    // 按比例分区
    //val resultStream = dataStream.rescale
    // 广播操作，将数据集分发每个分区中
    //dataStream.broadcast()

    // 4、指定数据输出位置
    resultStream.print()

    // 5、触发任务执行
    env.execute("Flink Partition Demo")
  }
}
